import uniqueId from '@form-create/utils/lib/unique';
import {localeProps, makeRequiredRule} from '../../utils';

const label = '身份证';
const name = 'jd-idcard';

export default {
    icon: 'icon-idcard',
    label,
    name,
    rule({t}) {
        return {
            type: 'input',
            field: 'SFZ',
            title: '身份证',
            info: '',
            $required: false,
            validate:[{
                type:'idcard',
                required:true,
                'trigger': 'change',
                validator:function(rule,val,d){
                    val && !/(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{7}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}$)/.test(val) ? d(true) : d()
                },
                message:"请输入正确的身份证号"
            }],
            props: {}
        };
    },
    props(_, {t}) {
        return localeProps(t, name + '.props', [
            {type: 'input', field: 'placeholder', title: '占位文本'},
            makeRequiredRule(), 
            {
                type: 'row',
                props: {gutter: 5},
                children: [
                    {
                        type: 'col',
                        props: {span: 12},
                        children: [
                            {type: 'JdIconSelect',field: 'prefixIcon',title: '头部图标',style: { width: '200px'}}, 
                        ]
                    },
                    {
                        type: 'col',
                        props: {span: 12},
                        children: [
                            {type: 'JdIconSelect', field: 'suffixIcon', title: '尾部图标',style: { width: '200px'}}, 
                        ]
                    }
                ]
            },
            {
                type: 'col',
                props: {span: 12},
                children: [
                    {type: 'switch', field: 'showWordLimit', title: '显示字数'}, 
                ]
            },
            {
                type: 'col',
                props: {span: 12},
                children: [
                    {type: 'inputNumber', field: 'maxlength', title: '最大长度', props: {min: 0, max: 500, controlsPosition:'right', width: '100%'}}
                ]
            }, 
            {
                type: 'col',
                props: {span: 12},
                children: [
                    {type: 'switch', field: 'disabled', title: '是否禁用'}, 
                ]
            },
            {
                type: 'col',
                props: {span: 12},
                children: [
                    {type: 'switch', field: 'readonly', title: '是否只读'}, 
                ]
            },
        ]);
    }
};
